package com.sld.concrete.vehicle.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import org.springframework.stereotype.Service;
import com.sld.concrete.vehicle.mapper.InfoVehicleMapper;
import com.sld.concrete.vehicle.domain.InfoVehicle;
import com.sld.concrete.vehicle.service.IInfoVehicleService;
import com.ruoyi.common.core.text.Convert;

import javax.annotation.Resource;

/**
 * 车辆管理Service业务层处理
 * 
 * @author topviewers
 * @date 2022-03-13
 */
@Service
public class InfoVehicleServiceImpl implements IInfoVehicleService 
{
    @Resource
    private InfoVehicleMapper infoVehicleMapper;

    /**
     * 查询车辆管理
     * 
     * @param id 车辆管理主键
     * @return 车辆管理
     */
    @Override
    public InfoVehicle selectInfoVehicleById(Long id)
    {
        return infoVehicleMapper.selectInfoVehicleById(id);
    }

    /**
     * 查询车辆管理列表
     * 
     * @param infoVehicle 车辆管理
     * @return 车辆管理
     */
    @DataScope(deptAlias = "d")
    @Override
    public List<InfoVehicle> selectInfoVehicleList(InfoVehicle infoVehicle)
    {
        return infoVehicleMapper.selectInfoVehicleList(infoVehicle);
    }

    /**
     * 新增车辆管理
     *
     * @param infoVehicle 车辆管理
     * @return 结果
     */
    @Override
    public int insertInfoVehicle(InfoVehicle infoVehicle) throws Exception {
        //重复车牌无法录入
        InfoVehicle exist = infoVehicleMapper.queryVehicleByPlateNo(infoVehicle.getPlateNo());
        if (exist != null) {
            throw new Exception("车牌重复");
        }
        infoVehicle.setCreateTime(DateUtils.getNowDate());
        infoVehicle.setCreateUser(ShiroUtils.getLoginName());
        return infoVehicleMapper.insertInfoVehicle(infoVehicle);
    }

    /**
     * 修改车辆管理
     * 
     * @param infoVehicle 车辆管理
     * @return 结果
     */
    @Override
    public int updateInfoVehicle(InfoVehicle infoVehicle)
    {
        infoVehicle.setUpdateTime(DateUtils.getNowDate());
        return infoVehicleMapper.updateInfoVehicle(infoVehicle);
    }

    /**
     * 批量删除车辆管理
     * 
     * @param ids 需要删除的车辆管理主键
     * @return 结果
     */
    @Override
    public int deleteInfoVehicleByIds(String ids)
    {
        return infoVehicleMapper.deleteInfoVehicleByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除车辆管理信息
     * 
     * @param id 车辆管理主键
     * @return 结果
     */
    @Override
    public int deleteInfoVehicleById(Long id)
    {
        return infoVehicleMapper.deleteInfoVehicleById(id);
    }
}
